<template>
	<view>
		<find-page2 :pages="pages"></find-page2>
	</view>
</template>

<script>
	import findPage from "@/component/find/find.vue"
	import findPage2 from "@/component/find/find2.vue"
			import myrequest from "@/untils/request.js"
	export default {
		components:{
			findPage,
			findPage2
		},
		data() {
			return {
				startnum:2,
				pageSize:5,
				pageNum:2,
				pages:[],
				isend:false
			}
		},
		methods: {
			getdata(){
				myrequest.getpage(this.$store.state.token,this.pageNum,this.pageSize)
				.then(r=>{
					if(r.data.data.items.length){
						this.pages = this.pages.concat(r.data.data.items)
					}else{  //没有了
						this.isend =true
					}
					
				})
			},
			reachDown(){
				if(!this.isend){
						this.pageNum++
						this.getdata()
				}else{
					uni.showToast({
						title:"已经到底了！！",
						icon:"error"
					})
				}
				
			},
			refresh(){
				this.pages.length = 0
				this.pageNum=this.startnum
				this.isend = false
				myrequest.getpage(this.$store.state.token,this.pageNum,this.pageSize)
				.then(r=>{
					this.pages = r.data.data.items
				}).then(()=>{
					uni.stopPullDownRefresh()
				})
			}
			
		},onLoad() {
			myrequest.getpage(this.$store.state.token,this.pageNum,this.pageSize)
			.then(r=>{
				if(r.statusCode === 401){
					uni.showToast({
						title:"您还没有登录!",
						icon:"error"
					})
					return
				}
				this.pages = r.data.data.items
			})
		},
		onReachBottom() {
			this.reachDown()
		},
		onPullDownRefresh() {
			console.log("find刷新");
			this.refresh()
		}
	}
</script>

<style>

</style>
